import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import quillEditor from 'vue-quill-editor'
import './registerServiceWorker'
import 'element-ui/lib/theme-chalk/index.css';
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import * as filters from '@/utils/filters'
import echarts from 'echarts'
import { throttle, debounce } from '@/utils/throttle-debounce'
import Axios from 'axios';
const AXIOS = Axios.create({
  // 配置前缀公共地址
  // baseURL: 'http://shiyansong.cn:8888/api/private/v1/',
  baseURL: process.env.VUE_APP_SERVE,
  // 超时配置
  timeout: 1000 * 100
})
Vue.prototype.$Http = AXIOS
// 配置请求拦截器
AXIOS.interceptors.request.use(config => {
  console.log('请求拦成功', config);
  const token = localStorage.getItem('token')
  config.headers.Authorization = token
  return config
}, err => {
  console.log('请求失败', err)
  return Promise.reject(err)
})
// 配置响应拦截器
AXIOS.interceptors.response.use(res => {
  switch (meta.status) {
    case 200:
      Message.success(meta.msg)
      break;
    case 201:
      Message.success(meta.msg)
      break;
    case 204:
      Message.success(meta.msg)
      break;
    case 400:
      Message.error(meta.msg)
      break;
    case 401:
      Message.error(meta.msg)
      break;
    case 403:
      Message.error(meta.msg)
      break;
    case 404:
      Message.error(meta.msg)
      break;
    case 422:
      Message.error(meta.msg)
      break;
    case 500:
      Message.error(meta.msg)
      break;
    default:
      Message.success(meta.msg)

  }
  return res.data
},
  err => {
    console.log('响应失败', err)
    return Promise.reject(err)
  })


Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.prototype.$throttle = throttle
Vue.prototype.$debounce = debounce

Vue.config.productionTip = false
Vue.use(quillEditor)
Vue.use(ElementUI);
Vue.prototype.$echarts = echarts
new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')
